// Programming_Scala/src/ch12/node.scala

package ch12

abstract trait Node[ +A ] {
  def payload: A
  def next: Node[ A ]
}

case class ::[ +A ]( val payload: A, val next: Node[ A ] ) extends Node[ A ] {
  override def toString = String.format( "( %s :: %s )", payload.toString, next.toString )
}

object NilNode extends Node[ Nothing ] {
  def payload = throw new NoSuchElementException( "no payload in NilNoade" )
  def next = throw new NoSuchElementException( "no next in NilNode" )

  override def toString = "*"
}

